package com.getword.controller;


import com.getword.pojo.User;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    @Autowired
    private EurekaClient eurekaClient;
    // 访问提供者,用于访问rest接口
    @Autowired
    private RestTemplate restTemplate;
    private String url = "http://localhost:7900/user/";

    @GetMapping("/order/{id}")
    public User getOrder(@PathVariable("id") Long id){
//        InstanceInfo instance = eurekaClient.getNextServerFromEureka("PROVIDER-USER", false);
//        String homePageUrl = instance.getHomePageUrl();
        User user = restTemplate.getForObject("http://PROVIDER-USER/user/" + id, User.class);
        return user;
    }
}
